home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / d_texture.pro < prev    next >
Text File  |  1997-07-08  |  20KB  |  609 lines

  1. ;$Id: d_texture.pro,v 1.19 1997/04/17 22:10:17 tremblay Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       d_texture.pro
  9. ;
  10. ;  CALLING SEQUENCE: d_texture
  11. ;
  12. ;  PURPOSE:
  13. ;       Shows the texture mapping.
  14. ;
  15. ;  MAJOR TOPICS: texture mapping
  16. ;
  17. ;  CATEGORY:
  18. ;       IDL 5.0
  19. ;
  20. ;  INTERNAL FUNCTIONS and PROCEDURES:
  21. ;       pro texture_Event      -  Event handler
  22. ;       pro texture_Cleanup    -  Cleanup
  23. ;       pro d_texture            -  Main procedure
  24. ;
  25. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  26. ;       pro trackball__define   -  Create the trackball object
  27. ;       texture.txt
  28. ;       texture.tip
  29. ;       pro gettips                - Get the tips text structure..
  30. ;       pro widtips                - Create the widget text for tips.
  31. ;       pro sizetips               - Size the widget text for tips.
  32. ;       elev.dat
  33. ;       elev_t.dat
  34. ;
  35. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  36. ;
  37. ;  NAMED STRUCTURES:
  38. ;       none.
  39. ;
  40. ;  COMMON BLOCS:
  41. ;       none.
  42. ;
  43. ;  MODIFICATION HISTORY:
  44. ;       9/96,   DD   - Written.
  45. ;       10/96,  DAT  - New GUI.
  46. ;
  47. ;-
  48. ;----------------------------------------------------------------------------
  49. ;
  50. ;
  51. ;  Purpose:  Event handler.
  52. ;
  53. pro texture_event, $
  54.     sEvent
  55.  
  56.     ;  Quit the application using the close box.
  57.     ;
  58.     if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
  59.         'WIDGET_KILL_REQUEST') then begin
  60.         WIDGET_CONTROL, sEvent.top, /DESTROY
  61.         RETURN
  62.     endif
  63.  
  64.     WIDGET_CONTROL, sEvent.id, GET_UVALUE= uvalue
  65.  
  66.     case uvalue of
  67.  
  68.         ;  Zoom by translating the object
  69.         ;
  70.         'FNUMBER' : begin
  71.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  72.             WIDGET_CONTROL, sState.wBase, SENSITIVE=0
  73.         dSlider = sEvent.value - sState.sliderVal
  74.         sState.sliderVal = sEvent.value
  75.  
  76.             ;  Maximum translation is 12.8 * 20(slider value) /100
  77.             ;  in the view normalized coorrdinates.
  78.             ;
  79.         sState.oSurfaceModel->Translate, 0., 0., dSlider/100.*12.8
  80.  
  81.         sState.oWindow->Draw, sState.oView
  82.             WIDGET_CONTROL, sState.wBase, SENSITIVE=1
  83.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  84.         end   ;  of FNUMBER
  85.  
  86.         ;  Change the surface height  acordingly to the slider value.
  87.         ;
  88.         'FHEIGHT' : begin
  89.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  90.             WIDGET_CONTROL, sState.wBase, SENSITIVE=0
  91.         dSlider = sEvent.value - sState.sliderVal
  92.             heightRatio = FLOAT(sEvent.value) / sState.heightFactor
  93.             newData = sState.z1 * heightRatio
  94.             sState.oSurface->SetProperty, DATAZ=newData
  95.         sState.oWindow->Draw, sState.oView
  96.             WIDGET_CONTROL, sState.wBase, SENSITIVE=1
  97.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  98.         end   ;  of FHEIGHT
  99.  
  100.         ;  Draw only the surface with the wire style.
  101.         ;
  102.         'SURFACEONLY' : begin
  103.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  104.             WIDGET_CONTROL, sState.wBase, SENSITIVE=0
  105.             WIDGET_CONTROL, sState.wSurfButton, SENSITIVE=0
  106.             WIDGET_CONTROL, sState.wSurfTextureButton, SENSITIVE=1
  107.             sState.oSurface->SetProperty, TEXTURE_MAP=OBJ_NEW(), $
  108.                 STYLE=1
  109.             sState.oWindow->Draw, sState.oView
  110.             WIDGET_CONTROL, sState.wBase, SENSITIVE=1
  111.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  112.         end   ;  of SURFACEONLY
  113.  
  114.         ;  Draw  surface with the texture mapping.
  115.         ;
  116.         'SURFACETEXTURE' : begin
  117.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  118.             WIDGET_CONTROL, sState.wBase, SENSITIVE=0
  119.             sState.oSurface->SetProperty, $
  120.                 TEXTURE_MAP=sState.oImage, STYLE=2
  121.             WIDGET_CONTROL, sState.wSurfButton, SENSITIVE=1
  122.             WIDGET_CONTROL, sState.wSurfTextureButton, SENSITIVE=0
  123.             sState.oWindow->Draw, sState.oView
  124.             WIDGET_CONTROL, sState.wBase, SENSITIVE=1
  125.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  126.         end   ;  of SURFACETEXTURE
  127.  
  128.         ;  Reset the initial translation and orientation.
  129.         ;
  130.         'RESET' : begin
  131.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  132.             WIDGET_CONTROL, sState.wBase, SENSITIVE=0
  133.             sState.oSurfaceRotationModel->SetProperty, $
  134.                 TRANSFORM=sState.initRotTM
  135.             sState.oSurfaceModel->SetProperty, $
  136.                 TRANSFORM=sState.initSurTM
  137.             WIDGET_CONTROL, sState.wHeightSlider, $
  138.                 SET_VALUE=5 
  139.             WIDGET_CONTROL, sState.wZoomSlider, $
  140.                 SET_VALUE=0 
  141.             sState.oWindow->Draw, sState.oView
  142.             WIDGET_CONTROL, sState.wBase, SENSITIVE=1
  143.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  144.         end   ;  of RESET
  145.  
  146.         ;  Handle the event generated within the drawing area
  147.         ;
  148.         'DRAW': begin
  149.  
  150.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  151.  
  152.             ;  Expose.
  153.             ;
  154.             if (sEvent.type eq 4) then begin
  155.                 sState.oWindow->Draw, sState.oView
  156.                 WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  157.                 RETURN
  158.             endif
  159.  
  160.             ;  Handle trackball update
  161.             ;
  162.             bHaveTransform = sState.oTrack->Update(sEvent, TRANSFORM=qmat )
  163.                 if (bHaveTransform NE 0) then begin
  164.                     sState.oSurfaceRotationModel->GetProperty, TRANSFORM=t
  165.                     mt = t # qmat
  166.                     sState.oSurfaceRotationModel->SetProperty,TRANSFORM=mt
  167.                 endif
  168.  
  169.             ;  Button press.
  170.             ;
  171.             if (sEvent.type EQ 0) then begin
  172.                 sState.btndown = 1B
  173.                 sState.oWindow->setproperty, QUALITY=0
  174.                 WIDGET_CONTROL, sState.wDraw, /DRAW_MOTION
  175.             endif
  176.  
  177.             ;  Button motion.
  178.             ;
  179.             if ((sEvent.type eq 2) and (sState.btndown eq 1b)) then begin
  180.                 if (bHaveTransform) then begin
  181.                     sState.oWindow->Draw, sState.oView
  182.                 endif
  183.             endif
  184.  
  185.             ;  Button release.
  186.             ;
  187.             if (sEvent.type eq 1) then begin
  188.                 if (sState.btndown EQ 1b) then begin
  189.                     sState.oWindow->SetProperty, QUALITY=2
  190.                     sState.oWindow->Draw, sState.oView
  191.                 endif
  192.                 sState.btndown = 0b
  193.                 WIDGET_CONTROL, sState.wDraw, DRAW_MOTION=0
  194.             endif
  195.  
  196.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  197.  
  198.         end   ;   of DRAW
  199.  
  200.         'QUIT' : BEGIN
  201.             WIDGET_CONTROL, sEvent.top, /DESTROY
  202.         end   ; of QUIT
  203.  
  204.         'ABOUT' : BEGIN
  205.  
  206.             ;  Verify that there is only one instance of XDisplayFile
  207.             ;
  208.             if (Xregistered('XDisplayFile') NE 0) then RETURN
  209.                 XDisplayFile, filepath("texture.txt", $
  210.                     SUBDIR=['examples','demo','demotext']), $
  211.                 DONE_BUTTON='Done', $
  212.                 TITLE="Texture", $
  213.                 GROUP=sEvent.top, WIDTH=54, HEIGHT=14
  214.         end   ; of ABOUT
  215.  
  216.     endcase
  217.  
  218. end
  219.  
  220. ;-----------------------------------------------------------------
  221. ;
  222. ;    PURPOSE : cleanup procedure. restore colortable, destroy objects.
  223. ;
  224. pro Texture_Cleanup, wBase
  225.  
  226.     WIDGET_CONTROL, wBase, GET_UVALUE=sState, /NO_COPY
  227.  
  228.     ;  Destroy the top objects.
  229.     ;
  230.     OBJ_DESTROY, sState.oView
  231.     OBJ_DESTROY, sState.oText
  232.     OBJ_DESTROY, sState.oFont
  233.     OBJ_DESTROY, sState.oImage
  234.     OBJ_DESTROY, sState.oTrack
  235.     OBJ_DESTROY, sState.oContainer
  236.  
  237.     ;  Restore the color table.
  238.     ;
  239.     TVLCT, sState.colorTable
  240.  
  241.     if widget_info(sState.groupBase, /valid) then $
  242.         widget_control, sState.groupBase, /map
  243.  
  244. end   ;  of Texture_Cleanup
  245.  
  246. ;-----------------------------------------------------------------
  247. ;
  248. ;    PURPOSE : show the texture mapping capability
  249. ;
  250. PRO d_texture, $
  251.     TEXCOORDS = texcoords, $   ; IN: (opt) texture coordinates
  252.     GROUP=group, $             ; IN: (opt) group identifier
  253.     APPTLB = appTLB            ; OUT: (opt) TLB of this application
  254.  
  255.     ; Check the validity of the group identifier.
  256.     ;
  257.     ngroup = N_ELEMENTS(group)
  258.     if (ngroup NE 0) then begin
  259.         check = WIDGET_INFO(group, /VALID_ID)
  260.         if (check NE 1) then begin
  261.             print,'Error, the group identifier is not valid'
  262.             print, 'Return to the main application'
  263.             RETURN
  264.         endif
  265.         groupBase = group
  266.     endif else groupBase = 0L
  267.  
  268.     ;  Set up dimensions of the drawing (viewing) area.
  269.     ;
  270.     device, GET_SCREEN_SIZE=scr
  271.     xdim = scr(0)*0.6
  272.     ydim = xdim*0.8
  273.  
  274.     ;  Get the current color vectors to restore 
  275.     ;  when this application is exited.
  276.     ;
  277.     TVLCT, savedR, savedG, savedB, /GET
  278.  
  279.     ;  Build color table from color vectors
  280.     ;
  281.     colorTable = [[savedR],[savedG],[savedB]]
  282.  
  283.     ;  Get the tips.
  284.     ;
  285.     sText = getTips(filepath('texture.tip', $
  286.         SUBDIR=['examples','demo', 'demotext']) )
  287.  
  288.     ;  Create widgets.
  289.     ;
  290.     if (N_ELEMENTS(group) EQ 0) then begin
  291.         wBase = WIDGET_BASE(/COLUMN, $
  292.             TITLE="Texture Mapped Terrain", $
  293.             XPAD=0, YPAD=0, $
  294.             /TLB_KILL_REQUEST_EVENTS, $
  295.             TLB_FRAME_ATTR=1, Mbar=barBase)
  296.     endif else begin
  297.         wBase = WIDGET_BASE(/COLUMN, $
  298.             TITLE="Texture Mapping", $
  299.             GROUP_LEADER=group, $
  300.             XPAD=0, YPAD=0, $
  301.             /TLB_KILL_REQUEST_EVENTS, $
  302.             TLB_FRAME_ATTR=1, Mbar=barBase)
  303.     endelse
  304.  
  305.         ;  Create the menu bar. It contains the file/quit,
  306.         ;  edit/ shade-style, help/about.
  307.         ;
  308.         wFileButton = WIDGET_BUTTON(barBase, VALUE='File', /MENU)
  309.  
  310.             wQuitButton = WIDGET_BUTTON(wFileButton, $
  311.                 VALUE='Quit', UVALUE='QUIT')
  312.  
  313.          ;  Offer two options : surface only , surface with texture
  314.          ;
  315.          wOptionButton = WIDGET_BUTTON(barBase, VALUE='Options', /MENU)
  316.  
  317.              wSurfButton = WIDGET_BUTTON(wOptionButton, $
  318.                  VALUE = 'Surface Only', UVALUE='SURFACEONLY')
  319.  
  320.              wSurfTextureButton = WIDGET_BUTTON(wOptionButton, $
  321.                  VALUE='Surface with Texture', UVALUE='SURFACETEXTURE')
  322.  
  323.              wResetButton = WIDGET_BUTTON( wOptionButton, $
  324.                  VALUE='Reset', UVALUE='RESET')
  325.  
  326.          ;  Create the menu bar item help that contains the about button
  327.          ;
  328.          wHelpButton = WIDGET_BUTTON(barBase, VALUE='About', /HELP, /MENU)
  329.  
  330.              wAboutButton = WIDGET_BUTTON(wHelpButton, $
  331.                  VALUE='About Texture Mapping', UVALUE='ABOUT')
  332.  
  333.          ;  Create a sub base of the top base (wBase)
  334.          ;
  335.          subBase = WIDGET_BASE(wBase, COLUMN=2)
  336.  
  337.  
  338.              ;  Create the left Base that contains the functionality buttons
  339.              ;  Notably the object list and the option list
  340.              ;
  341.              wLeftbase = WIDGET_BASE(subBase, /ALIGN_CENTER, /COLUMN)
  342.  
  343.                  wZoomBase = WIDGET_BASE(wLeftBase, /COLUMN)
  344.  
  345.                      wZoomBaseLabel = WIDGET_LABEL(wZoomBase, $
  346.                          VALUE = "Zoom")
  347.  
  348.                      wZoomValueBase = WIDGET_BASE(wZoomBase, $
  349.                          /COLUMN, /FRAME)
  350.  
  351.                          wSliderBase = WIDGET_BASE(wZoomValueBase, $
  352.                              /COLUMN, /ALIGN_CENTER)
  353.  
  354.                              wFastLbl = WIDGET_LABEL(wSliderBase, $
  355.                                  VALUE='+', $
  356.                                  /ALIGN_CENTER)
  357.    
  358.                              wZoomSlider = WIDGET_SLIDER(wSliderBase,$
  359.                                  /ALIGN_CENTER, $
  360.                                  MINIMUM=0, MAXIMUM=20, $
  361.                                  /SUPPRESS_VALUE, $
  362.                                  UVALUE='FNUMBER', /VERTICAL)
  363.  
  364.                              wSlowLbl = WIDGET_LABEL(wSliderBase, $
  365.                                  VALUE='-', $
  366.                                  /ALIGN_CENTER)
  367.  
  368.                  wHeightBase = WIDGET_BASE(wLeftBase, /COLUMN)
  369.  
  370.                      wHeightBaseLabel = WIDGET_LABEL(wHeightBase, $
  371.                          VALUE="Height")
  372.  
  373.                      wHeightValueBase = WIDGET_BASE(wHeightBase, $
  374.                          /COLUMN, /FRAME)
  375.  
  376.                          wSlider2Base = WIDGET_BASE(wHeightValueBase, $
  377.                              /COLUMN, /ALIGN_CENTER)
  378.  
  379.                              wPlusLbl = WIDGET_LABEL(wSlider2Base, $
  380.                                  VALUE='+', $
  381.                                  /ALIGN_CENTER)
  382.    
  383.                              wHeightSlider = WIDGET_SLIDER(wSlider2Base,$
  384.                                  /ALIGN_CENTER, $
  385.                                  VALUE=5, $
  386.                                  MINIMUM=0, MAXIMUM=10, $
  387.                                  /SUPPRESS_VALUE, $
  388.                                  UVALUE='FHEIGHT', /VERTICAL)
  389.  
  390.                              wMinusLbl = WIDGET_LABEL(wSlider2Base, $
  391.                                  VALUE='-', $
  392.                                  /ALIGN_CENTER)
  393.  
  394.              ;  Create the right Base that has the drawing area
  395.              ;
  396.              wRightBase = WIDGET_BASE(subBase, /COLUMN)
  397.  
  398.                  ;  Draw area.
  399.                  ;
  400.                  wDraw = WIDGET_DRAW(wRightBase, $
  401.                      GRAPHICS_LEVEL=2, $
  402.                      XSIZE=xdim, YSIZE=ydim, /BUTTON_EVENTS, $
  403.                      UVALUE='DRAW', $
  404.                      RETAIN=0, /EXPOSE_EVENT)
  405.         ;  Create tips texts.
  406.         ;
  407.         wStatusBase = WIDGET_BASE(wBase, MAP=0, /ROW)
  408.  
  409.             nWidgets = 2
  410.             wText = LONARR(nWidgets)
  411.             widTips, wStatusBase, sText.text, XSIZE=36, $
  412.                 YSIZE=3, NWIDGETS=nWidgets, wText
  413.  
  414.     ;  Realize the base widget. 
  415.     ;
  416.     WIDGET_CONTROL, wBase, /REALIZE
  417.  
  418.     ;  Returns the top level base in the appTLB keyword
  419.     ;
  420.     appTLB = wBase
  421.  
  422.     ;  Size the tips widgets.
  423.     ;
  424.     sizeTips, wBase, wText, wStatusBase
  425.  
  426.     WIDGET_CONTROL, wBase, SENSITIVE=0
  427.  
  428.     ;  Grab the window id of the drawable.
  429.     ;
  430.     WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
  431.  
  432.     ;  Put centerize the surface.
  433.     ;
  434.     bias = -0.5
  435.  
  436.     myview = [0+bias, 0+bias, 1, 1]
  437.  
  438.     ;  Create view.  
  439.     ;
  440.     oView = OBJ_NEW('idlgrview', $
  441.         PROJECTION=2, EYE=3, ZCLIP=[1.5,-1.5], $
  442.         VIEWPLANE_RECT=myview, COLOR=[0,0,0])
  443.  
  444.     ;  Create a centerd starting up text.
  445.     ;
  446.     textLocation = [myview[0]+0.5*myview[2], myview[1]+0.5*myview[3]]
  447.  
  448.     ;  Create and display the PLEASE WAIT text.
  449.     ;
  450.     oFont = OBJ_NEW('IDLgrFont', 'Helvetica', SIZE=18)
  451.     oText = OBJ_NEW('IDLgrText', $
  452.         'Starting up  Please wait...', $
  453.         ALIGN=0.5, $
  454.         LOCATION=textLocation, $
  455.         COLOR=[255,255,0], FONT=oFont)
  456.  
  457.     ;  Create model.
  458.     ;
  459.     oTopModel = OBJ_NEW('idlgrmodel')
  460.     oSurfaceModel = OBJ_NEW('idlgrmodel')
  461.     oSurfaceRotationModel = OBJ_NEW('idlgrmodel')
  462.     oTopModel->Add, oSurfaceModel
  463.     oSurfaceModel->Add, oSurfaceRotationModel
  464.  
  465.     ;  Place the model in the view..
  466.     ;
  467.     oView->Add, oTopModel
  468.  
  469.     oTopModel->Add, oText
  470.  
  471.     oWindow->Draw, oView
  472.  
  473.     WIDGET_CONTROL, wBase, /HOURGLASS
  474.  
  475.     ;  Scale the top model to fit the viewing area.
  476.     ;
  477.     sct = 0.5
  478.     oTopModel->Scale, sct, sct, sct
  479.  
  480.     ;  Surface data is read from elevation data file.
  481.     ;
  482.     z = BYTARR(64,64, /NOZERO)
  483.     OPENR, lun, filepath('elevbin.dat', $
  484.         SUBDIR=['examples','demo','demodata']), $
  485.         /GET_LUN
  486.     READU, lun, z
  487.     FREE_LUN, lun
  488.  
  489.     sz = SIZE(z)
  490.     maxx = sz(1) - 1
  491.     maxy = sz(2) - 1
  492.     maxz = MAX(z, MIN=minz)
  493.  
  494.     ;  Compute coordinate conversion to normalize.
  495.     ;
  496.     xs = [0+bias, 1.0/maxx]
  497.     ys = [0+bias, 1.0/maxy]
  498.  
  499.     minz2 = minz - 1
  500.     maxz2 = maxz + 1 
  501.     zs = [-minz2/(maxz2-minz2)+bias, 1.0/(maxz2-minz2)]
  502.  
  503.     ;  Create texture map.
  504.     ;
  505.     READ_JPEG, filepath('elev_t.jpg', $
  506.         SUBDIR=['examples','demo','demodata']), $
  507.         idata, TRUE=3
  508.  
  509.     oImage = OBJ_NEW('IDLgrImage', idata, INTERLEAVE=2)
  510.  
  511.     textureCoordinates = FLTARR(2,64,64)
  512.  
  513.     ;  Scale the texture coordinates
  514.     ;
  515.     for j=0,63 do begin
  516.         for i=0,63 do begin
  517.             textureCoordinates(0,i,j) = FLOAT(i)/32.0
  518.             textureCoordinates(1,i,j) = FLOAT(j)/32.0
  519.         endfor
  520.     endfor
  521.  
  522.     ;  Create the surface object
  523.     ;
  524.     oSurface = OBJ_NEW('IDLgrSurface', z, style=2, shading=1, $
  525.     COLOR=[255,255,255], TEXTURE_MAP=oImage, $
  526.     XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs)
  527.     oSurfaceRotationModel->Add, oSurface
  528.  
  529.     z1 = z/2.0
  530.     oSurface->SetProperty, DATAZ=z1
  531.  
  532.     if (N_ELEMENTS(texcoords) NE 0) then begin
  533.     oSurface->SetProperty, TEXTURE_COORD=textureCoordinates
  534.     end
  535.  
  536.     ;  Create a light.
  537.     ;
  538.     oLight1 = OBJ_NEW('IDLgrLight', TYPE=0, $
  539.         INTENSITY=1., COLOR=[255,255,255])
  540.     oTopModel->Add, oLight1
  541.     oLight2 = OBJ_NEW('IDLgrLight', LOCATION=[-2,2,-2], TYPE=1)
  542.     oTopModel->Add, oLight2
  543.  
  544.     ;  Rotate to standard view for first draw.
  545.     ;
  546.     oSurfaceRotationModel->Rotate, [1,0,0],-90
  547.     oSurfaceRotationModel->Rotate, [0,1,0],30
  548.     oSurfaceRotationModel->Rotate, [1,0,0],30
  549.  
  550.     oSurfaceRotationModel->GetProperty, TRANSFORM=initRotTM
  551.     oSurfaceModel->GetProperty, TRANSFORM=initSurTM
  552.  
  553.     ;  Add the trackball object for interactive change
  554.     ;  of the scene orientation
  555.     ;
  556.     oTrack = OBJ_NEW('Trackball', [xdim/2.0, ydim/2.0], xdim/2.0)
  557.  
  558.     oContainer = OBJ_NEW('IDLgrContainer')
  559.     oContainer->Add, oView
  560.     oContainer->Add, oTrack
  561.  
  562.  
  563.     WIDGET_CONTROL, wSurfTextureButton, SENSITIVE=0
  564.  
  565.     ;  Create the state structure.
  566.     ;
  567.     sState = { $
  568.         btndown: 0b, $                  ; Mouse button 0=pressed, other: pressed
  569.         HeightFactor: 5.0, $            ; Slider value factor for height
  570.         wDraw: wDraw, $                 ; Widget draw ID
  571.         OSurfaceModel: oSurfaceModel, $ ; Surface models
  572.         OSurfaceRotationModel: oSurfaceRotationModel, $
  573.         OSurface: oSurface, $           ; Surface object
  574.         OView: oView, $                 ; View object
  575.         InitRotTM: initRotTM, $         ; Initial Rotation of the surface
  576.         InitSurTM: initSurTM, $         ; Surface initial transformation matrix 
  577.         sliderVal: 0, $                 ; Zoom slider value
  578.         WHeightSlider: wHeightSlider, $ ; Data height slider value
  579.         WZoomSlider: wZoomSlider, $     ; Zoom slider ID
  580.         WBase : wbase, $                ; top level base
  581.         WSurfTextureButton: wSurfTextureButton, $ : Surface + texture button
  582.         WSurfButton: wSurfButton, $     ; Surfaced only button
  583.         OImage: oImage, $               ; Image object
  584.         ColorTable: colorTable, $       ; Color table to restore.
  585.         Z1: z1, $                       ; Data array
  586.         OTrack: oTrack, $               ; Trackball object
  587.         OText: oText, $                 ; Text object
  588.         OFont: oFont, $                 ; Font object
  589.         OContainer: oContainer, $       ; Container object
  590.         OWindow: oWindow, $             ; Window object
  591.         groupBase: groupBase $          ; Base of Group Leader
  592.      }  
  593.  
  594.     WIDGET_CONTROL, wBase, SET_UVALUE=sState, /NO_COPY
  595.  
  596.     ; Draw the screen
  597.     ;
  598.     oTopModel->Remove, oText
  599.     oWindow->Draw, oView
  600.  
  601.     WIDGET_CONTROL, wBase, SENSITIVE=1
  602.  
  603.     XMANAGER, 'd_texture', wBase, $
  604.         Event_Handler='texture_event', $
  605.         /NO_BLOCK, $
  606.         CLEANUP='texture_Cleanup'
  607.  
  608. end   ;   of  d_texture
  609.